﻿<UserControl
    x:Class="Stopwatch.View.BasicStopwatch"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Stopwatch.View"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400"
    xmlns:viewmodel="using:Stopwatch.ViewModel">

    <UserControl.Resources>
        <viewmodel:StopwatchViewModel x:Name="viewModel"/>
        <viewmodel:TimeNumberFormatConverter x:Name="timeNumberFormatConverter"/>
        <viewmodel:BooleanVisibilityConverter x:Key="visibilityConverter"/>
        <viewmodel:BooleanNotConverter x:Key="notConverter"/>
    </UserControl.Resources>

    <Grid DataContext="{StaticResource ResourceKey=viewModel}">
        <StackPanel>
            <TextBlock>
                <Run>Elapsed time: </Run>
                <Run Text="{Binding Hours,
                    Converter={StaticResource timeNumberFormatConverter}}"/>
                <Run>:</Run>
                <Run Text="{Binding Minutes,
                    Converter={StaticResource timeNumberFormatConverter}, ConverterParameter=d2}"/>
                <Run>:</Run>
                <Run Text="{Binding Seconds,
                    Converter={StaticResource timeNumberFormatConverter}}"/>
                        </TextBlock>
                        <TextBlock>
                <Run>Lap time: </Run>
                <Run Text="{Binding LapHours,
                    Converter={StaticResource timeNumberFormatConverter}}"/>
                <Run>:</Run>
                <Run Text="{Binding LapMinutes,
                    Converter={StaticResource timeNumberFormatConverter}, ConverterParameter=d2}"/>
                <Run>:</Run>
                <Run Text="{Binding LapSeconds,
                    Converter={StaticResource timeNumberFormatConverter}}"/>
            </TextBlock>
            <StackPanel Orientation="Horizontal">
                <Button IsEnabled="{Binding Running, Converter={StaticResource notConverter}}"
                    Click="StartButton_Click">Start</Button>
                <Button IsEnabled="{Binding Running}" Click="StopButton_Click">Stop</Button>
                <Button Click="ResetButton_Click">Reset</Button>
                <Button IsEnabled="{Binding Running}" Click="LapButton_Click">Lap</Button>
            </StackPanel>
            <TextBlock Text="Stopwatch is running"
                Visibility="{Binding Running, Converter={StaticResource visibilityConverter}}"
                Style="{StaticResource StopwatchRunningTextBlockStyle}"/>
        </StackPanel>
    </Grid>
</UserControl>